<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>

<script type="text/javascript">

		var baseEditUrl = "${ctx}/plupmodule/edit";
		var baseDeleteUrl = "${ctx}/plupmodule/deletemodel";
		var baseViewUrl = "${ctx}/plupmodule/moduleDetail";
		var editUrl ="";
		var viewUrl = "",deleteUrl = "", moduleId = "";

		function rowClickAfter(rowIndex,curModuleId, curAppName) {
			moduleId = curModuleId;
			editUrl = baseEditUrl + "?module_id=" + moduleId;
			viewUrl = baseViewUrl + "?id=" + moduleId;
			deleteUrl = baseDeleteUrl + "?id=" + moduleId;
			var  arrId = document.getElementsByName("check");
			arrId[rowIndex -1 ].checked=true;
		}

		function doModuleEdit(){

			if (moduleId == "") {
				alert("请选择要编辑的模块！");
			} else {
				Utils.forward( editUrl);
			}			
		}

		function doModuleView(){
			if (moduleId == "") {
				alert("请选择要查看的模块！");
			} else {
				Utils.forward(viewUrl);
			}			
		}		
		
        function doModuleCreate(){            
        	window.location.href="${pageContext.request.contextPath }/plupmodule/create";
        }
        
        function  doModuleDelete(){
			if (moduleId == "") {
				alert("请选择要删除的模块！");
			} else {
	        	if (confirm("确定删除吗")==true){
	            	ajaxRequest();
	        	}				
			}            
        }
        function ajaxRequest() {      
            alert(deleteUrl);      
      	 $.ajax({
     			type:'post',
     			url:deleteUrl,
     		    dataType: "json",     		   
     		    async: false,
     		    data:$("#modulelistForm").serialize(),
     			success:function(data){//返回json结果
         			var addstate=data.model.flag;
         			if(addstate==0){
         				  alert("删除失败！");
         			}else{
         				alert("删除成功");
         					window.location.href="${pageContext.request.contextPath }/plupmodule/modulelist";
             			}     			
     				}
     		});
     	 
            }
       
</script>
</head>
<body>
<div class="panel panel-default">
   <div class="panel-heading">
      <h3 class="panel-title">
          请输入查询条件
      </h3>
   </div>
   <div class="panel-body">
<form class="form-horizontal" role="form" id="modulelistForm" name="modulelistForm" action="${pageContext.request.contextPath }/plupmodule/modulelist" method="post">
                      
                       <div class="form-group">
                          <label class="col-xs-1 control-label" for="ds_username">模块编号</label>
                          <div class="col-xs-3">
                             <input class="input-sm form-control" id="moduleid" name="moduleid" value="${moduleid}" type="text"/>
                          </div>
                          <label class="col-xs-1 control-label" for="ds_password">模块名称</label>
                          <div class="col-xs-3">
 									<input class="input-sm  form-control" id="modulename" name="modulename"  value="${modulename}" type="text"/>
                          </div>
                          <div class="col-xs-4">
                          	 <button  type="submit" class="btn btn-default btn-sm" >查询</button>                          
                          </div>
                       </div>
            
   </div>
</div>
			<div class="op-btn">
				<input type="button" class="btn btn-default" value="创建模块"  onclick="doModuleCreate()"/>
				<input type="button" class="btn btn-default" value="删除模块"  onclick="doModuleDelete()"/>
				<input type="button" class="btn btn-default" value="编辑模块"  onclick="doModuleEdit()"/>
				<input type="button" class="btn btn-default" value="查看模块"  onclick="doModuleView()"/>		
			</div>		
			<table class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center" class="active">
						<td>选择</td>
						<td>模块编号</td>
						<td>模块名称</td>
						<td>模块首页</td>
						<td>最近修改日期</td>
					</tr>
				</thead>				
				<tbody>
				<c:forEach items="${modulelist}" var="moduleEntity">
				<tr align="center">
							<td><input type="radio" name="check" id="check" value="15"></input></td>
							<td>${moduleEntity.module_id}</td>
							<td>${moduleEntity.module_name}</td>
							<td>${moduleEntity.module_index_page_id}</td>
							<td>${moduleEntity.last_modify_date}</td>
						</tr>  				
				</c:forEach> 						
				</tbody>
			</table>
			<%@ include file="/page/page.jsp" %>
			
		</form>
	<script language="javascript">
	    var preRow = null;
		$('tbody tr').bind('click', function() {
	
			var rowIndex = $(this).prevAll().length+1;
			if(rowIndex <1) return;
			
			if(preRow != null){
				preRow.removeClass("active");
			}
			$(this).addClass("active");
			preRow = $(this);
			
			// 行单击后事件(传入行号，应用ID,应用名称信息)
		rowClickAfter(rowIndex,
					$(this).find("td").eq(1).text(),$(this).find("td").eq(2).text());
		});
	</script>
</body>
</html>
